<template>
  <div>
    <el-table :data="tableData" style="height: 600px; overflow: auto;">
      <el-table-column prop="ruleName" label="规则名称" style="width: 10%"/>
      <el-table-column prop="explain" label="填写说明"/>
      <el-table-column prop="value" label="规则值" style="width: 10%" align="center"/>
      <el-table-column prop="score" label="得分" style="width: 10%" align="center"/>
    </el-table>
  </div>
</template>
<style>
  .el-table .cell {
    white-space: pre-line; /*保留换行符*/
  }
</style>
<script>
  export default {
    name: 'RuleInfo',
    props: [
      'data'
    ],
    data() {
      return {
        tableData: null
      }
    },
    created() {
      const examRuleBean = this.data.examRuleBean
      this.tableData = [{
        ruleName: '考试时长',
        explain: '考试的时间(秒),0代表不限制',
        value: examRuleBean.time,
        score: '-'
      }, {
        ruleName: '考试次数',
        explain: '最多允许考试的次数（1-999）',
        value: examRuleBean.frequency,
        score: '-'
      }, {
        ruleName: '补考次数',
        explain: '无有效成绩，可补考次数（0-999）',
        value: examRuleBean.overFrequency,
        score: '-'
      }, {
        ruleName: '成绩计算',
        explain: '多个有效成绩的处理方式：\n' +
          '0:最小值 1: 最大值  2:均值',
        value: examRuleBean.resultMethod,
        score: '-'
      }, {
        ruleName: '成绩精度',
        explain: '成绩精度:保留几位小数（秒）\n' +
          '例如：2.1-1位， 2.11-2位， 2-0位',
        value: examRuleBean.resultAccuracy,
        score: '-'
      }, {
        ruleName: '成绩单位',
        explain: '-',
        value: examRuleBean.resultUnit,
        score: '-'
      }, {
        ruleName: '成绩取整',
        explain: '成绩记录为毫秒，取秒的规则：\n' +
          '0：向下取整，例如5.412->5.4\n' +
          '1：向上取整，例如5.412->5.5\n' +
          '2：四舍五入，例如5.412->5.4\n' +
          '                5.545->5.5',
        value: examRuleBean.resultScale,
        score: '-'
      }, {
        ruleName: '减考得分',
        explain: '减考的考生得分',
        value: '-',
        score: examRuleBean.reduceScore
      }, {
        ruleName: '免考得分',
        explain: '免考的考生得分',
        value: '-',
        score: examRuleBean.exemptScore
      }]

      if (this.data.examName === '1000米/800米'
        || this.data.examName === '足球'
        || this.data.examName === '篮球'
        || this.data.examName === '游泳') {
        const levelsData = this.getLevelsData('男', 0, examRuleBean)
        this.tableData.push(...levelsData)
        const levelsData2 = this.getLevelsData('女', 9, examRuleBean)
        this.tableData.push(...levelsData2)
      }
      if (this.data.examName === '排球' || this.data.examName === '跳绳') {
        this.tableData[4] = {
          ruleName: '成绩精度',
          explain: '-',
          value: examRuleBean.resultAccuracy,
          score: '-'
        }
        this.tableData[6] = {
          ruleName: '成绩取整',
          explain: '-',
          value: examRuleBean.resultScale,
          score: '-'
        }
        const levelsData = this.getLevelsData('男', 0, examRuleBean)
        this.tableData.push(...levelsData)
        const levelsData2 = this.getLevelsData('女', 9, examRuleBean)
        this.tableData.push(...levelsData2)
      }
      if (this.data.examName === '跳远') {
        this.tableData[4] = {
          ruleName: '成绩精度',
          explain: '成绩精度:保留几位小数（cm）\n' +
            '例如：2.1-1位， 2.11-2位， 2-0位',
          value: examRuleBean.resultAccuracy,
          score: '-'
        }
        this.tableData[6] = {
          ruleName: '成绩取整',
          explain: '-',
          value: examRuleBean.resultScale,
          score: '-'
        }
        const levelsData = this.getLevelsData('男', 0, examRuleBean)
        this.tableData.push(...levelsData)
        const levelsData2 = this.getLevelsData('女', 9, examRuleBean)
        this.tableData.push(...levelsData2)
      }
      if (this.data.examName === '引体向上') {
        this.tableData[4] = {
          ruleName: '成绩精度',
          explain: '-',
          value: examRuleBean.resultAccuracy,
          score: '-'
        }
        this.tableData[6] = {
          ruleName: '成绩取整',
          explain: '-',
          value: examRuleBean.resultScale,
          score: '-'
        }
        const levelsData = this.getLevelsData('男', 0, examRuleBean)
        this.tableData.push(...levelsData)
      }
      if (this.data.examName === '仰卧起坐') {
        this.tableData[4] = {
          ruleName: '成绩精度',
          explain: '-',
          value: examRuleBean.resultAccuracy,
          score: '-'
        }
        this.tableData[6] = {
          ruleName: '成绩取整',
          explain: '-',
          value: examRuleBean.resultScale,
          score: '-'
        }
        const levelsData = this.getLevelsData('女', 0, examRuleBean)
        this.tableData.push(...levelsData)
      }
    },
    methods: {
      getLevelsData(gender, startI, examRuleBean) {
        const levelData = [{
          ruleName: gender + '-等级' + examRuleBean.levels[startI].level,
          explain: '成绩小于等于该值（' + examRuleBean.resultUnit + '）',
          value: examRuleBean.levels[startI].result,
          score: examRuleBean.levels[startI].score
        }]
        startI++
        for (let i = 2; i < 10; i++) {
          let levelInfo = {
            ruleName: gender + '-等级' + examRuleBean.levels[startI].level,
            explain: '成绩大于上个等级，小于等于该值（' + examRuleBean.resultUnit + '）',
            value: examRuleBean.levels[startI].result,
            score: examRuleBean.levels[startI].score
          }
          startI++
          levelData.push(levelInfo)
        }
        return levelData
      }
    }
  }
</script>
